package com.qianfeng.dbsm.controller;

import com.qianfeng.dbsm.common.ResponseData;
import com.qianfeng.dbsm.entity.TbProductCosmetics;
import com.qianfeng.dbsm.entity.TbProductDistribution;
import com.qianfeng.dbsm.service.TbProductCosmeticsService;
import com.qianfeng.dbsm.service.TbProductDistributionService;
import com.qianfeng.dbsm.service.TbProductInventoryService;
import com.qianfeng.dbsm.vo.UpdateProductNum;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("productManager")
public class ProductController {

    @Autowired
    TbProductCosmeticsService tbProductCosmeticsService;
    @Autowired
    TbProductDistributionService tbProductDistributionService;
    @Autowired
    TbProductInventoryService tbProductInventoryService;


    @ApiOperation(value = "搜索查看单个商品", notes = "通过商品id查询")
    @GetMapping("queryProduct")
    public ResponseData queryProduct(int productId){
       ResponseData rd=new ResponseData();
       TbProductCosmetics one = tbProductCosmeticsService.queryById(productId);
       rd.setData(one);
       return rd;
   }

    @ApiOperation(value = "商品推销商", notes = "返回推销商详情")
    @PostMapping("distribution")
    public ResponseData queryDistribution(int productId,int memberId){
        ResponseData rd=new ResponseData();
        List<TbProductDistribution> lists = tbProductDistributionService.queryByProductAndUser(productId, memberId);
        rd.setData(lists);
        return rd;
    }

    @ApiOperation(value = "删除指定商品", notes = "根据商品id删除商品")
    @DeleteMapping("del")
    public ResponseData deleteProduct(int productId){
        ResponseData rd=new ResponseData();
        boolean b = tbProductCosmeticsService.deleteById(productId);
        return rd;
    }


    @ApiOperation(value = "修改库存", notes = "根据商品id,属性库存id修改")
    @PutMapping("updateNum")
    public ResponseData updateProductNum(int productId,int inventoryId,int num){
        UpdateProductNum updateProductNum = tbProductInventoryService.updateProductNum(productId, inventoryId, num);
        ResponseData rd=new ResponseData();
        rd.setData(updateProductNum);
        return rd;
    }

}
